Skip to content

chore: drop redundant toReplayable overrides and derive Method token from enum name#189

Merged
OmarAlJarrah merged 2 commits into
mainfrom
chore/174-request-toreplayable-method-token
Jun 28, 2026
Merged

chore: drop redundant toReplayable overrides and derive Method token from enum name#189
OmarAlJarrah merged 2 commits into
mainfrom
chore/174-request-toreplayable-method-token

Conversation

@OmarAlJarrah

Copy link
Copy Markdown
Member

Removes a small cluster of declarations in http/request that restate behavior they already inherit. All three changes are behavior-preserving.

Changes

RequestBody — drop the no-op toReplayable overrides on the replayable bodies

The base RequestBody.toReplayable() short-circuits to this whenever isReplayable() is true. The three private replayable bodies (BufferRequestBody, ByteArrayRequestBody, ResettableInputStreamRequestBody) all return true from isReplayable() and then re-declare an override that returns this — exactly what they'd inherit. The overrides are removed. (IoProvider stays imported; the base toReplayable still references it.)

FileRequestBody — drop the no-op override and its now-unused import

Same restatement, on the public body. The inherited toReplayable() still returns this — the same FileRequestBody — so transports that type-check is FileRequestBody for the zero-copy sendfile(2) path keep matching. With the override gone, import …io.IoProvider is unreferenced and is removed in the same change.

Method — derive the wire token from the enum name

Every constant passed a string literal identical to its own enum name (GET("GET", …), …), and toString() returned that string — which is what the default enum toString() already produces. The constructor parameter and the nine duplicated literals are dropped; the token is now a computed val method: String get() = name, and the default toString() stands. getMethod() remains public and callable, so request.method.method (okhttp adapter, Digest auth) and request.method.name (instrumentation) render the same token as before.

API

Two explicit overrides become inherited/default, so their lines drop from sdk-core/api/sdk-core.api (regenerated and committed):

  • FileRequestBody.toReplayable (…IoProvider;)…
  • Method.toString ()Ljava/lang/String;

getMethod() is unchanged. The Method enum constructor is implicitly private and not in the snapshot, so dropping its parameter is not itself an API change.

Verification

  • :sdk-core:compileKotlin, ktlint, and apiCheck (against the regenerated snapshot) pass.
  • Method, RequestBody, and FileRequestBody test suites pass — including MethodTest's toString()-equals-token check, which holds under the default enum toString().

Closes #174

…from name

Remove a cluster of declarations in http/request that restate inherited
behavior. All changes are behavior-preserving.

- RequestBody: the base toReplayable() short-circuits to `this` whenever
  isReplayable() is true. The three private replayable bodies
  (BufferRequestBody, ByteArrayRequestBody, ResettableInputStreamRequestBody)
  each return true from isReplayable() and then override toReplayable to
  return `this` — exactly the inherited behavior. Drop the overrides.
- FileRequestBody: same no-op override on the public body. The inherited
  toReplayable() still returns `this` (the FileRequestBody), so the
  transport-side `is FileRequestBody` sendfile(2) fast path keeps matching.
  Removing it leaves the IoProvider import unreferenced, so drop that too.
- Method: every constant passed a wire-token string identical to its own
  enum name, and toString() returned that string — which is what the
  default enum toString() already produces. Drop the constructor parameter
  and the nine duplicated literals; expose the token as `method` computed
  from `name`, and let the default toString() stand. getMethod() stays
  public and callable.

Public API: FileRequestBody.toReplayable(IoProvider) and Method.toString()
were explicit overrides in the snapshot and are now inherited/default, so
both lines drop from sdk-core.api (regenerated). getMethod() is unchanged.

Closes #174
Moving the wire-token from a constructor parameter to a body-level
computed property surfaces detekt's MemberNameEqualsClassName (the rule
only inspects body-declared members, so it was dormant while method was a
constructor val). The accessor is kept for API compatibility and the
token genuinely is the method's name, so suppress the rule rather than
rename.
@OmarAlJarrah OmarAlJarrah merged commit 3421dc2 into main Jun 28, 2026
@OmarAlJarrah OmarAlJarrah deleted the chore/174-request-toreplayable-method-token branch June 28, 2026 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

http/request: remove redundant toReplayable overrides and derive Method token from enum name

1 participant